 <template>
  <div class="swipercom">
    <div class="swiper-container" id="swiperCom">
      <div class="swiper-wrapper">
        <div class="swiper-slide" v-for="(item, i) in imgs" :key="i">
          <img :src="item.pic" />
        </div>
      </div>
      <!-- 如果需要分页器 -->
      <div class="swiper-pagination"></div>
    </div>
  </div>
</template>
<script>
import Swiper from "swiper";
import "swiper/css/swiper.css";
import { getBanners } from "../api/index";

export default {
  data() {
    return {
      imgs: [],
    };
  },
  async mounted() {
    var mySwiper = new Swiper("#swiperCom", {
      direction: "horizontal",
      loop: true, // 循环模式选项

      // 如果需要分页器
      pagination: {
        el: ".swiper-pagination",
        clickable: true,
      },
    });
    let res = await getBanners(2);
    this.imgs = res.data.banners;
  },
};
</script>
<style lang="less">
.swipercom {
  .swiper-container {
    width: 7.1rem;
    height: 2.8rem;
    border-radius: 0.1rem;

    .swiper-slider {
      width: 100%;
    }
    .swiper-pagination-bullet-active {
      background: orangered;
    }
  }
}
</style>